package io.renren.modules.goods.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.goods.entity.GoodsInfoEntity;
import io.renren.modules.goods.service.GoodsInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import javax.annotation.Resource;


/**
 * 商品表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2024-08-13 15:15:14
 */
@RestController
@RequestMapping("sys/goodsinfo")
public class GoodsInfoController {
    @Resource
    private GoodsInfoService goodsInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:goodsinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:goodsinfo:info")
    public R info(@PathVariable("id") Integer id){
        GoodsInfoEntity goodsInfo = goodsInfoService.getById(id);

        return R.ok().put("goodsInfo", goodsInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:goodsinfo:save")
    public R save(@RequestBody GoodsInfoEntity goodsInfo){
        goodsInfoService.save(goodsInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:goodsinfo:update")
    public R update(@RequestBody GoodsInfoEntity goodsInfo){
        ValidatorUtils.validateEntity(goodsInfo);
        goodsInfoService.updateById(goodsInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:goodsinfo:delete")
    public R delete(@RequestBody Integer[] ids){
        goodsInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
